package com.xiaoyu.awakening.ai.search.config;

import lombok.SneakyThrows;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.Resource;

import java.nio.charset.Charset;

/**
 * awk agents bean 配置
 *
 * @author wangxiaoyu
 * @date 2025/8/7 11:49
 * @since v1.0
 */
@Configuration
public class AwkAgentsConfiguration {


    @Value("classpath:prompts/intention.md")
    private Resource intentionPrompt;

    @Value("classpath:prompts/searchPlan.md")
    private Resource searchPlanPrompt;

    @Value("classpath:prompts/llmRerankPlan.md")
    private Resource llmRerankPrompt;

    @Value("classpath:prompts/translate.md")
    private Resource translatePrompt;


    /**
     * intentionAgent Agent ChatClient Bean
     *
     * @param chatClientBuilder ChatClientBuilder McpAsyncClient and the locally configure
     *                          ToolCallbackProviders.
     * @return ChatClient
     */
    @SneakyThrows
    @Bean
    @Primary
    public ChatClient intentionAgent(ChatClient.Builder chatClientBuilder) {
        return chatClientBuilder.defaultSystem(intentionPrompt.getContentAsString(Charset.defaultCharset())).build();
    }

    /**
     * searchPlanAgent
     *
     * @param chatClientBuilder ChatClientBuilder McpAsyncClient and the locally configure
     *                          ToolCallbackProviders.
     * @return ChatClient
     */
    @SneakyThrows
    @Bean
    public ChatClient searchPlanAgent(ChatClient.Builder chatClientBuilder) {
        return chatClientBuilder.defaultSystem(searchPlanPrompt.getContentAsString(Charset.defaultCharset())).build();
    }

    @SneakyThrows
    @Bean
    public ChatClient llmRerankAgent(ChatClient.Builder chatClientBuilder) {
        return chatClientBuilder.defaultSystem(llmRerankPrompt.getContentAsString(Charset.defaultCharset())).build();
    }

    @SneakyThrows
    @Bean
    public ChatClient translateAgent(ChatClient.Builder chatClientBuilder) {
        return chatClientBuilder.defaultSystem(translatePrompt.getContentAsString(Charset.defaultCharset())).build();
    }
}
